package ca.ericslandry.client.widget;

import java.util.HashSet;

import ca.ericslandry.client.mvp.validation.HasValidators;
import ca.ericslandry.client.mvp.validation.Validatable;
import ca.ericslandry.client.mvp.validation.Validator;

import com.google.gwt.user.client.ui.TextBox;

public class ValidatableTextBox extends TextBox implements Validatable, HasValidators {
	private HashSet<Validator> validators = new HashSet<Validator>();

	@Override
	public void addValidator(Validator validator) {
		validators.add(validator);
	}

	@Override
	public boolean validate() {
		boolean valid = true;

		for (Validator validator : validators) {
			if (!validator.validate()) {
				valid = false;
			}
		}

		return valid;
	}
}
